package com.xwj.coupon.user.common.enums;

import com.xwj.coupon.user.service.handler.excel.amount.ComputeAmountHandler;
import com.xwj.coupon.user.service.handler.excel.amount.DiscountComputeAmountHandler;
import com.xwj.coupon.user.service.handler.excel.amount.FixedComputeAmountHandler;
import com.xwj.coupon.user.service.handler.excel.amount.ThresholdComputeAmountHandler;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * @Author: XuWenjie
 * @Date: 2025-08-21
 * @Description: ComputeAmountHandlerEnum
 */
@RequiredArgsConstructor
public enum ComputeAmountHandlerEnum {

    /**
     * 满减
     */
    THRESHOLD(DiscountTypeEnum.THRESHOLD_DISCOUNT, new ThresholdComputeAmountHandler()),

    /**
     * 折扣
     */
    DISCOUNT(DiscountTypeEnum.DISCOUNT_COUPON, new DiscountComputeAmountHandler()),

    /**
     * 固定金额
     */
    FIXED(DiscountTypeEnum.FIXED_DISCOUNT, new FixedComputeAmountHandler());

    @Getter
    private final DiscountTypeEnum type;
    @Getter
    private final ComputeAmountHandler handler;

    public static ComputeAmountHandler getHandler(DiscountTypeEnum type) {
        for (ComputeAmountHandlerEnum handlerEnum : values()) {
            if (handlerEnum.getType().equals(type)) {
                return handlerEnum.getHandler();
            }
        }
        return null;
    }
}
